import 'package:bi_project/db/hi_cache.dart';
import 'package:bi_project/http/core/hi_net.dart';
import 'package:bi_project/http/request/base_request.dart';
import 'package:bi_project/http/request/login_request.dart';
import 'package:bi_project/http/request/register_request.dart';

class LoginDao {
  static const BOARDING_PASS = "boarding-pass";

  static login(String userName, String password) {
    return _send(userName, password);
  }

  static registration(
      String userName, String password, String imoocId, String orderId) {
    return _send(userName, password, imoocId: imoocId, orderId: orderId);
  }

  static _send(String userName, String password, {imoocId, orderId}) async {
    // BaseRequest request;
    var testResult;
    if (imoocId != null && orderId != null) {
      // request = RegisterRequest();
    } else {
      // request = LoginRequest();
      testResult = {
        "code": 0,
        "data": "3009049jkljjajkdhklbkj9",
        "msg": "login success"
      };
    }
    // request
    //     .add("userName", userName)
    //     .add("password", password)
    //     .add("imoocId", imoocId ?? "")
    //     .add("orderId", orderId ?? "");
    // var result = await HiNet.getInstance().fire(request);
    var result = testResult;
    if (result['code'] == 0 && result['data'] != null) {
      HiCache.getInstance().setString(BOARDING_PASS, result['data']);
    }
    return result;
  }

  static getBoardingPass() {
    return HiCache.getInstance().get(BOARDING_PASS);
  }
}
